<?php
/*
 * @Author: wangzhichao
 * @Date: 2025-01-26 10:04:16
 * @LastEditors: your Name
 * @LastEditTime: 2025-01-26 14:54:22
 * @Description: 
 */
require_once './src/config.php';
require_once './src/WeChat.php';

use Project\WeChat;

// 获取当前页面 URL
$currentUrl = "https://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";

// 初始化微信类
$wechat = new WeChat($appId, $appSecret);

// 获取 JS-SDK 配置
$wxConfig = $wechat->generateJsSdkConfig($currentUrl);

// 输出到前端页面
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
  <title>2025天河城春节不打烊</title>
  <link rel="stylesheet" href="./css/index.css?v=202501260944">
</head>
<body>
  <div class="gif_box">
    <div class="gif_img_box">
      <div class="gif_last_btn" id="gif_last_btn">点击领取更多福利</div>
      <img src="./img/tianhecheng_last.jpg" id="gif_last" alt="">
      <img src="./img/tianhecheng.gif" id="gifImg" alt="">
    </div>
  </div>
  <div class="container">
    <div class="container_title">我的<span class="yellow mlr6">「红包封面」</span>见面礼</div>
    <div class="package_box package_box_0 show">
      <div class="package_box_title"></div>
      <div class="package_box_desc"></div>
      <div class="package_media_box"></div>
      <div class="package_button_box">
        <div class="package_button"></div>
      </div>
      <div class="package_share_box">
        <div class="share_icon"></div>
        <div class="share_text">邀请大家一起抽取</div>
      </div>
    </div>
    <div class="package_box package_box_1">
      <div class="package_box_title"></div>
      <div class="package_box_desc"></div>
      <div class="package_media_box"></div>
      <div class="package_button_box">
        <div class="package_button"></div>
      </div>
      <div class="package_share_box">
        <div class="share_icon"></div>
        <div class="share_text">邀请大家一起抽取</div>
      </div>
    </div>
    <div class="package_list" id="package_list"></div>
    <div class="package_tips_box"></div>
  </div>
  <div class="share_mask">
    <div class="share_mask_icon">
      <img src="./img/arrow.png" alt="">
    </div>
    <div class="share_mask_text">
      <div>请点击右上角...</div>
      <div>分享给朋友或者分享到朋友圈</div>
    </div>
  </div>
  <div class="dialog_box">
    <div class="dialog_mask"></div>
    <div class="dialog_content">
      <div class="dialog_title">天河城祝您新春快乐!</div>
      <div class="dialog_desc">2025天河城春节不打烊，各类好货等你来逛!</div>
      <div class="dialog_btn_box">
        <div class="dialog_btn">领取福利</div>
      </div>
    </div>
  </div>

  <script src="//res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
  <script src="./js/flexible.js"></script>
  <script src="./js/jquery.min.js"></script>
  <script src="./js/index.js?v=202501260944"></script>
  <script>
    // 从 PHP 获取微信配置
    var wxConfig = <?php echo json_encode($wxConfig); ?>;
    var initWeChat = function() {
      wx.config({
        debug: false, // 开启调试模式
        appId: wxConfig.appId,
        timestamp: wxConfig.timestamp,
        nonceStr: wxConfig.nonceStr,
        signature: wxConfig.signature,
        jsApiList: ['checkJsApi', 'updateAppMessageShareData', 'updateTimelineShareData']
      });

      wx.ready(function () {
        wx.updateAppMessageShareData({
          title: '分享标题',
          desc: '分享描述',
          link: wxConfig.url,
          imgUrl: 'https://example.com/image.jpg',
          success: function () {
            alert('分享成功！');
          }
        });
        wx.updateTimelineShareData({ 
          title: '分享标题', // 分享标题
          link: '分享描述', // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
          imgUrl: 'https://example.com/image.jpg',
          success: function () {
            // 设置成功
          }
        })
      });

      wx.error(function (res) {
        console.error('微信 JS-SDK 错误: ', res);
      });
    }
    initWeChat()
  </script>
</body>
</html>